﻿Public Class ClientesForm
    '
    '
    'PREGUNTAR---> COMO HACER QUE COPIE A LOS TEXTBOX CON CTRL+C Ó CTRL+V
    'PREGUNTAR---> ESCRIBE SIEMPRE EL PRIMER REGISTRO DE LA BD EN LOS TEXTBOX DEL LOGIN
    '
    '
    '
    Private Const CaracteresValidos As String = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ "
    Private Const CaracteresValidosDNI As String = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789 "
    Private Sub CargarClientes()
        'Cargamos los datos de los clientes del dataset al CLIENTETableAdapter
        Me.CLIENTETableAdapter.Fill(Me.ScrumDataSet.CLIENTE)
    End Sub
    Private Sub LimpiarDatosClientes()
        For Each mControl As Control In grbTocarEmpleado.Controls
            If mControl.GetType = GetType(TextBox) Then TryCast(mControl, TextBox).Clear()
            If mControl.GetType = GetType(MaskedTextBox) Then TryCast(mControl, MaskedTextBox).Clear()
        Next
    End Sub
    Private Sub ClientesForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CargarClientes()
        txtDNI.Focus()

    End Sub

    Private Sub btnAñadir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAñadir.Click

        If txtNombre.Text = "" Or txtPrimerApellido.Text = "" Or txtSegundoApellido.Text = "" Or txtDNI.Text = "" Then
            MessageBox.Show("No puede estar en blanco")
            Exit Sub
        End If
        Try
            CLIENTETableAdapter.Insert(txtDNI.Text, txtNombre.Text, txtPrimerApellido.Text, txtSegundoApellido.Text)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Exit Sub
        End Try
        CargarClientes()
        LimpiarDatosClientes()

    End Sub

    Private Sub btnModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModificar.Click
        Try
            CLIENTETableAdapter.Update(txtDNI.Text, txtNOMBRE.Text, txtPrimerApellido.Text, txtSegundoApellido.Text, DNITextBox.Text, NOMBRETextBox.Text, Primer_ApellidoTextBox.Text, Segundo_ApellidoTextBox.Text)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        LimpiarDatosClientes()
        CargarClientes()
    End Sub

    Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorrar.Click
        Try
            CLIENTETableAdapter.Delete(DNITextBox.Text, NOMBRETextBox.Text, Primer_ApellidoTextBox.Text, Segundo_ApellidoTextBox.Text)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        CargarClientes()
    End Sub

    Private Sub BorrarTodas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BorrarTodas.Click
        Try
            ScrumDataSet.CLIENTE.Clear()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Exit Sub
        End Try
        CargarClientes()
    End Sub

    Private Sub btnVolver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVolver.Click
        Me.Close()
    End Sub

    Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        LimpiarDatosClientes()
    End Sub

    Private Sub txtDNI_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)

        If Not Char.IsLetterOrDigit(e.KeyChar) And e.KeyChar <> vbBack Then
            e.Handled = True
        End If
    End Sub


    Private Sub txtNombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNombre.KeyPress
        If Not Char.IsLetter(e.KeyChar) And e.KeyChar <> vbBack Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtPrimerApellido_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPrimerApellido.KeyPress


        If Not Char.IsLetter(e.KeyChar) And e.KeyChar <> vbBack Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtSegundoApellido_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSegundoApellido.KeyPress
        If Not Char.IsLetter(e.KeyChar) And e.KeyChar <> vbBack Then
            e.Handled = True
        End If
    End Sub


End Class